package com.atguigu.wc.transform;


import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;


/**
 * @Author:GaoFei
 * @Description:
 * @Date:Created in 18:11
 * @Modified By:
 */
public class BaseTransform1 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> fileDataStreamSource = env.readTextFile("D:\\1BIGDATA\\spark-streaming\\Flink\\src\\main\\resources\\sensor.txt");
        // map
        DataStream<Integer> map = fileDataStreamSource
                .map(String::length);

        // filter
        DataStream<String> sensor = fileDataStreamSource
                .filter(fil -> fil.startsWith("sensor"));
        sensor.print();
        env.execute();
    }

    private static void flatMapTest(DataStreamSource<String> fileDataStreamSource) {
        DataStream<String> stringSingleOutputStreamOperator = fileDataStreamSource
                .flatMap((k1, k2) -> {
                    String[] split = k1.split(",");
                    for (String s : split) {
                        k2.collect(s);
                    }
                });
        stringSingleOutputStreamOperator.print();
    }
}
